package com.vr.cloudpicture.model.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.vr.cloudpicture.model.entity.Picture;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 图片 VO
 *
 * @author hzh
 * @date 2025/05/07
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PictureVO implements Serializable {
    private static final long serialVersionUID = -6910090035096264918L;
    /**
     * id
     */
    private Long id;

    /**
     * 图片 url
     */
    private String url;

    /** 缩略图 URL */
    private String thumbnailUrl;
    /** 预览图 URL */
    private String previewUrl;

    /**
     * 图片名称
     */
    private String name;

    /**
     * 简介
     */
    private String introduction;

    /**
     * 分类
     */
    private String category;

    /**
     * 标签
     */
    private List<String> tags;

    /**
     * 图片体积
     */
    private Long picSize;

    /**
     * 图片宽度
     */
    private Integer picWidth;

    /**
     * 图片高度
     */
    private Integer picHeight;

    /**
     * 图片宽高比例
     */
    private Double picScale;

    /**
     * 图片格式
     */
    private String picFormat;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 编辑时间
     */
    private LocalDateTime editTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;
    /** 空间 ID */
    private Long spaceId;
    /** 图片颜色 */
    private String picColor;

    /** 创建的用户信息 */
    private UserVO user;

    /** 空间权限 */
    private List<String> permissions;

    public static Picture voToObj(PictureVO pictureVO) {
        if (pictureVO == null) {
            return null;
        }
        Picture picture = BeanUtil.toBean(pictureVO, Picture.class);
        picture.setTags(JSONUtil.toJsonStr(pictureVO.getTags()));
        return picture;
    }

    public static PictureVO objToVO(Picture picture) {
        if (picture == null) {
            return null;
        }
        PictureVO pictureVO = BeanUtil.toBean(picture, PictureVO.class);
        List<String> tagList = JSONUtil.toList(picture.getTags(), String.class);
        pictureVO.setTags(tagList);
        return pictureVO;
    }
}
